home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / misc / CharacterDecoder.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.0 KB  |  100 lines

  1. package sun.misc;
  2.  
  3. import java.io.ByteArrayInputStream;
  4. import java.io.ByteArrayOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.OutputStream;
  8. import java.io.PushbackInputStream;
  9. import java.nio.ByteBuffer;
  10.  
  11. public abstract class CharacterDecoder {
  12.    protected abstract int bytesPerAtom();
  13.  
  14.    protected abstract int bytesPerLine();
  15.  
  16.    protected void decodeBufferPrefix(PushbackInputStream var1, OutputStream var2) throws IOException {
  17.    }
  18.  
  19.    protected void decodeBufferSuffix(PushbackInputStream var1, OutputStream var2) throws IOException {
  20.    }
  21.  
  22.    protected int decodeLinePrefix(PushbackInputStream var1, OutputStream var2) throws IOException {
  23.       return this.bytesPerLine();
  24.    }
  25.  
  26.    protected void decodeLineSuffix(PushbackInputStream var1, OutputStream var2) throws IOException {
  27.    }
  28.  
  29.    protected void decodeAtom(PushbackInputStream var1, OutputStream var2, int var3) throws IOException {
  30.       throw new CEStreamExhausted();
  31.    }
  32.  
  33.    protected int readFully(InputStream var1, byte[] var2, int var3, int var4) throws IOException {
  34.       for(int var5 = 0; var5 < var4; ++var5) {
  35.          int var6 = var1.read();
  36.          if (var6 == -1) {
  37.             return var5 == 0 ? -1 : var5;
  38.          }
  39.  
  40.          var2[var5 + var3] = (byte)var6;
  41.       }
  42.  
  43.       return var4;
  44.    }
  45.  
  46.    public void decodeBuffer(InputStream var1, OutputStream var2) throws IOException {
  47.       int var4 = 0;
  48.       PushbackInputStream var5 = new PushbackInputStream(var1);
  49.       this.decodeBufferPrefix(var5, var2);
  50.  
  51.       while(true) {
  52.          try {
  53.             int var6 = this.decodeLinePrefix(var5, var2);
  54.  
  55.             int var3;
  56.             for(var3 = 0; var3 + this.bytesPerAtom() < var6; var3 += this.bytesPerAtom()) {
  57.                this.decodeAtom(var5, var2, this.bytesPerAtom());
  58.                var4 += this.bytesPerAtom();
  59.             }
  60.  
  61.             if (var3 + this.bytesPerAtom() == var6) {
  62.                this.decodeAtom(var5, var2, this.bytesPerAtom());
  63.                var4 += this.bytesPerAtom();
  64.             } else {
  65.                this.decodeAtom(var5, var2, var6 - var3);
  66.                var4 += var6 - var3;
  67.             }
  68.  
  69.             this.decodeLineSuffix(var5, var2);
  70.          } catch (CEStreamExhausted var8) {
  71.             this.decodeBufferSuffix(var5, var2);
  72.             return;
  73.          }
  74.       }
  75.    }
  76.  
  77.    public byte[] decodeBuffer(String var1) throws IOException {
  78.       byte[] var2 = new byte[var1.length()];
  79.       var1.getBytes(0, var1.length(), var2, 0);
  80.       ByteArrayInputStream var3 = new ByteArrayInputStream(var2);
  81.       ByteArrayOutputStream var4 = new ByteArrayOutputStream();
  82.       this.decodeBuffer(var3, var4);
  83.       return var4.toByteArray();
  84.    }
  85.  
  86.    public byte[] decodeBuffer(InputStream var1) throws IOException {
  87.       ByteArrayOutputStream var2 = new ByteArrayOutputStream();
  88.       this.decodeBuffer(var1, var2);
  89.       return var2.toByteArray();
  90.    }
  91.  
  92.    public ByteBuffer decodeBufferToByteBuffer(String var1) throws IOException {
  93.       return ByteBuffer.wrap(this.decodeBuffer(var1));
  94.    }
  95.  
  96.    public ByteBuffer decodeBufferToByteBuffer(InputStream var1) throws IOException {
  97.       return ByteBuffer.wrap(this.decodeBuffer(var1));
  98.    }
  99. }
  100.